package com.sky.edumanageapi.user.controller;

import com.sky.edumanageapi.base.response.JsonResult;
import com.sky.edumanageapi.user.pojo.dto.UserLogin;
import com.sky.edumanageapi.user.pojo.dto.UserRegister;
import com.sky.edumanageapi.user.pojo.vo.UserVO;
import com.sky.edumanageapi.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@Api(tags = "用户模块")
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("保存用户")
    @PostMapping("save")
    //前端用qs，转格式传参
    public JsonResult save(@RequestBody UserRegister userRegister) {

        log.debug("用户保存传入参数:{}", userRegister);

        userService.SaveUser(userRegister);

        return JsonResult.ok();
    }

    @ApiOperation("用户登录")
    @PostMapping("login")
    public JsonResult login(@RequestBody UserLogin userLogin) {

        log.debug("用户登录传入参数:{}", userLogin);

        return JsonResult.ok(userService.login(userLogin));
    }

    @ApiOperation("获取用户信息")
    @GetMapping("info")
    public JsonResult info(Integer id) {

        log.debug("获取用户信息，用户Id:{}", id);

        UserVO userVO = userService.info(id);

        return JsonResult.ok(userVO);

    }


}
